# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=rime-double-pinyin
pkgver=0.0.0.20190120
_commit=69bf85d4dfe8bac139c36abbd68d530b8b6622ea
pkgrel=1
pkgdesc="double-pinyin input for rime"
arch=('loong64' 'x86_64')
url="https://github.com/rime/rime-double-pinyin"
license=('LGPL')
# dependency for reverse lookup: rime-stroke
# dependency on dictionary: rime-luna-pinyin
depends=('rime-luna-pinyin' 'rime-stroke')
makedepends=('librime' 'rime-prelude' 'rime-essay')
source=("https://github.com/rime/rime-double-pinyin/archive/$_commit/rime-double-pinyin-$_commit.tar.gz")
sha512sums=('2ab98a7b804b2fa3d0a59fd0b9a8b79316caa3a2da070766359d550d1d56edf85d55874044409780a2a21d729a2a7e834fdcf9419eb0d34252acbdef304a5c40')

prepare() {
  cd $pkgname-$_commit
  # Link essentials
  for _f in $(pacman -Qql rime-prelude rime-essay rime-luna-pinyin | grep -v "/$"); do ln -sf $_f; done

  # Build binaries only for this package
  rm default.yaml
  cp /usr/share/rime-data/default.yaml ./
  sed -i -e '/- schema:/d' -e '/schema_list:/d' default.yaml
  echo "schema_list:" >> default.yaml
  ls *.schema.yaml | cut -d "." -f 1 | sed -e 's/\(.*\)/  - schema: \1/' >> default.yaml
}

build(){
  cd $pkgname-$_commit
  rime_deployer --build .
}

package() {
  cd $pkgname-$_commit
  find . -type l -delete
  rm {,build/}default.yaml user.yaml build/luna*
  install -Dm644 *.yaml -t "$pkgdir"/usr/share/rime-data/
  install -Dm644 build/* -t "$pkgdir"/usr/share/rime-data/build/
}
